-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fresh binding should shadow the def in expand #143141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
I don't understand why this works and how it fixes the issue. |
Also "shallow" -> "shadow" in the PR/commit messages and file names. |
There may be a bug if
rust/compiler/rustc_resolve/src/ident.rs Lines 320 to 328 in 86e05cd
|
@rustbot ready |
@bvanjoi |
Are you sure this cannot successfully resolve some names that should not be resolved? I need to test this with additional cases across different rib contexts. @rustbot author |
Reminder, once the PR becomes ready for a review, use |
tests/ui/resolve/fresh-should-shadow-definitation-in-decl-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-decl-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-macro-expand-in-block.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This PR was rebased onto a different master commit! Check out the changes with our |
This comment has been minimized.
This comment has been minimized.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang/rust#143141 (comment) and rust-lang/rust#143141 (comment). A couple of related cleanups are also added on top.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
These changes have wide-ranging implications. Could you please review whether the modifications in |
This comment has been minimized.
This comment has been minimized.
Reduce for #143141 (comment) macro_rules! m2 {
() => {{
static B: i32 = S;
42
}};
}
macro_rules! m {
() => {
static S: i32 = m2!();
};
}
fn main() {
m!();
} |
Using lexical scope at macro definition sites presents problematic outcomes:
What do you think? Should we introduce this change as a lint instead? @petrochenkov |
We'll definitely need a crater run and possibly a lint in the end. But at this point we probably rather need some more or less formal model of the rules that we want to achieve. #![allow(unused)]
fn f() {
let a = 0;
{
fn a() {}
{
let a = 0;
{
fn a() {}
#[macro_export]
macro_rules! mac {
() => {
let a = 0;
{
fn a() {}
{
let a = 0;
{
a; // use
}
}
}
};
}
}
}
}
}
fn main() {
let a = 0;
{
fn a() {}
{
let a = 0;
{
mac!();
}
}
}
} |
Have there been any mathematical models proposed, such as proof trees in type theory, to formally describe macro expansion? I've never encountered.😂 |
@bvanjoi |
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
I will try to answer this after reading this book. @rustbot ready |
Fixes #95237
r? @petrochenkov or @cjgillot